import Card from "antd/es/card/Card";
import { Button, Checkbox, Form, Input, Select, Space, Spin, InputNumber, Table, DatePicker } from 'antd';
import React, { useEffect, useRef, useState } from 'react';
import _ from 'lodash';
import { useParams,useHistory } from 'react-router-dom';
import JcdHandle from "../../../../../../utils/apis/JcdHandle";
import FetchHelper from "../../../../../../utils/helper/fetch-helper";
import JcyjApi from "../../../../../../utils/apis/JcyjApi";

export default function JcdEdit(props){
    const dynamicForms = [
      {
        "alias": "地点名",
        "name": "name",
        "type": "input"
    },
    {
        "alias": "地点全名",
        "name": "ps",
        "type": "input"
    },

    {
        "alias": "区县",
        "name": "qx",
        "type": "input"
    },
    {
        "alias": "开始时间",
        "name": "begin",
        "type": "input"
    },
    {
        "alias": "结束时间",
        "name": "end",
        "type": "input"
    },
    {
        "alias": "时间",
        "name": "tm",
        "type": "input"
    },
    {
        "alias": "类型",
        "name": "type",
        "type": "input"
    },
    {
        "alias": "平均气温",
        "name": "data",
        "type": "input"
    },
    ]
  const [idDatas, setIdDatas] = useState();
  const [loading, setLoading] = useState();
  const [form] = Form.useForm();
  const [xqDatas, setXqDatas] = useState();
  const [xqJson, setXqJson] = useState({})

  const [params, setParams] = useState({
    pageSize: 10,
    pageNum: 1,
    jcdlx: '河道'
  })
  const id=useParams()?.id;
  
//   useEffect(()=>{
//     JcdHandle.jcdXqDynamicApi().then(datas=>{
//       setXqDatas(datas)
//     })
//   },[])
//   useEffect(() => {

//     JcyjApi.yjList({ id: id }).then(resp => {
//         //console.log('22', ...resp.rows)
//         setIdDatas(resp.rows)
//         //let xqLookData=JSON.parse(resp.rows.xq)
//         form.setFieldsValue(//
//             ...resp.rows,
//         )
//     })
// }, [id, form])

  const history=useHistory();
  const quxiaoHandle=()=>{
    history.push(`/manager/Wbzjsj`)
  }

  const onFinish=(values)=>{
    //idDatas.xq=JSON.stringify(values.xqJson)
    const a=JSON.stringify(values)
    FetchHelper.putJson(`/admin-api/ybyj/yjsjb`,a).then(resp=>{ alert("修改成功") }).catch(err => { alert("修改失败") })
  }
    return <div className='layout-h h100' style={{
        overflow: "scroll"
      }}>
         <Card className='h100 fill' style={{
      height: "1500px"
    }}>
      <Form method="post"
        onFinish={onFinish}
        form={form}>
        <header style={{
          fontSize: 20,
          fontWeight: "bold"
        }}>预警数据信息</header>
        <hr />

        <div className="InputForm" style={{
          display: "flex",
          flexWrap: "wrap"
        }}>
          {dynamicForms !== undefined && dynamicForms.map((formItem) => {
            let node;
            switch (formItem.type) {
              case 'select':
                node = <Select></Select>;
                break;
              case 'input':
              default:
                node = <Input style={{
                  width: "90%"
                }}
                  onChange={(e) => {

                  }}

                />
            }
            return <div style={{
              flexBasis: "33%",
              marginBottom: "10px"
            }}><Form.Item
              label={formItem.alias}
              name={formItem.name}

              // rules={[
              //   {
              //     required: true,

              //   }
              // ]}

            >
                {node}
              </Form.Item></div>

          })}

        </div>
        {/* <div className="InputForm" style={{
          display: "flex",
          flexWrap: "wrap"
        }}>
          <header style={{
            fontSize: 20,
            fontWeight: "bold",

          }}>详情编辑:</header>
          <div className="InputForm" style={{
            display: "flex",
            flexWrap: "wrap"
          }}>
            {idDatas !== undefined && xqDatas !== undefined && xqDatas.map((formItem) => {
              let node;
              switch (formItem.type) {
                case 'select':
                  node = <Select></Select>;
                  break;
                case 'input':
                default:
                  node = <Input style={{
                    width: "90%"
                  }}
                    onChange={(e) => {

                    }}

                  />
              }

              return <div style={{
                flexBasis: "33%",
                marginBottom: "10px"
              }}>
                <Form.Item
                  label={formItem.alias}
                  name={['xqJson', formItem.name]}
                >
                  {node}
                </Form.Item></div>

            })}

          </div>
        </div> */}

        <div className="layout-h">
          <Button className="btn1" type="primary"
            htmlType="submit" 
            //onClick={baocunHandle}
          >新增</Button>

          <Button onClick={quxiaoHandle} className="btn2">返回</Button>
        </div>
      </Form>
    </Card>
      </div>
}